<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
</head>

<body>


    <div class="foot-t" id='foot-t'></div>
    <ul class="foot" id='foot'>
        <li tapmode>
            <img src="image/foot-0-h.png" id='I0' onclick="randomSwitchBtn( 0 );">
            <p onclick="randomSwitchBtn( 0 );">首页</p>
        </li>
        <li tapmode>
            <img src="image/foot-1.png" id='I1' onclick="randomSwitchBtn( 1 );">
            <p onclick="randomSwitchBtn( 1 );">出借</p>
        </li>
        <li tapmode>
            <img src="image/foot-2.png" id='I2' onclick="randomSwitchBtn( 2 );">
            <p onclick="randomSwitchBtn( 2 );">我的</p>
        </li>
        <li tapmode>
            <img src="image/foot-3.png" id='I3' onclick="randomSwitchBtn( 3 );">
            <p onclick="randomSwitchBtn( 3 );">更多</p>
        </li>
    </ul>

</body>
<script type="text/javascript" src="./script/aui-slide.js"></script>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript">
    function randomSwitchBtn(index) {
        var allImg = $(".foot li img");

        if (index == 2) {

            var userid = $api.getStorage('userid');
            if (!userid) {
                api.openWin({
                    name: 'login',
                    url: './login.html',
                });
            } else {
                api.setFrameGroupIndex({
                    name: 'nav',
                    index: index,
                    reload: true,
                });
                //更改底部点亮
                for (var i = 0; i < allImg.size(); i++) {
                    if (i == index) {
                        $(allImg[i]).attr("src", dw[i].address);
                    } else {
                        $(allImg[i]).attr("src", undw[i].address);
                    }
                }
            }
        } else {
            api.setFrameGroupIndex({
                name: 'nav',
                index: index,
                // reload: true,
            });
            //更改底部点亮
            for (var i = 0; i < allImg.size(); i++) {
                if (i == index) {
                    $(allImg[i]).attr("src", dw[i].address);
                } else {
                    $(allImg[i]).attr("src", undw[i].address);
                }
            }
        }
    }

    apiready = function() {
      $api.fixTabBar($api.byId('foot'));
      $('.foot').css('height', '70px');
        get_icon();


        api.openFrameGroup({
            name: 'nav',
            scrollEnabled: false,

            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                marginBottom: 70
            },
            frames: [{
                name: 'index',
                url: './index.html',
                bgColor: '#fff',
                vScrollBarEnabled:false,
            }, {
                name: 'licai_hqlc',
                url: './licai_hqlc.html',
                bgColor: '#fff',
                vScrollBarEnabled:false,

            }, {
                name: 'user',
                url: './user.html',
                bgColor: '#fff',
                vScrollBarEnabled:false,

            }, {
                name: 'more',
                url: './more.html',
                bgColor: '#fff',
                vScrollBarEnabled:false,

            }]
        }, function(ret, err) {

        });
        addListener();
        // 初始化极光推送
        addJKPush();
        registerjkPush();
    }

    function addJKPush() {
        var ajpush = api.require('ajpush');

        api.addEventListener({
            name: 'appintent'
        }, function(ret, err) {
            var ret = ret;
            var pageSign = ret.appParam.ajpush.extra.pageSign;
            // alert(pageSign);
        })

        if (api.systemType == "android") {
            ajpush.init(function(ret) {
                var param = {
                    alias: 'user1',
                    tags: ['user']
                };
                ajpush.bindAliasAndTags(param, function(ret) {

                });
            });
        }
    }

    function registerjkPush() {

        var ajpush = api.require('ajpush');
        var userid = $api.getStorage('userid');


        var ajpush = api.require('ajpush');
                    var param = {
                        alias: 'jkd',
                        tags: ['1']
                    };
        var registrationId = $api.getStorage('registrationId');
        if (registrationId == null) {
            ajpush.bindAliasAndTags(param, function(ret) {
                var statusCode = ret.statusCode;
                // alert(statusCode);
                if (statusCode == '0') {
                    ajpush.getRegistrationId(function(ret) {
                        var registrationId = ret.id;
                        $api.setStorage('registrationId', registrationId);

                    });
                }
            });
        }
    }


    function addListener() {
        api.addEventListener({
            name: 'resume'
        }, function(ret, err) {
            var gesture = $api.getStorage('is_gesture');
            if (gesture) {
                api.openWin({
                    name: 'h5unlock',
                    url: './h5unlock.html',
                    pageParam: {
                        name: 'home'
                    }
                });
            }
        });

    }

    function changeSelect() {
        api.closeToWin({
            name: 'root'
        });
        api.closeFrame({
            name: 'withdraw-top'
        });

        var userid = $api.getStorage('userid');
        if (!userid) {
            api.openWin({
                name: 'login',
                url: './login.html',
            });
            api.setFrameGroupIndex({
                name: 'nav',
                index: 0,
                reload: true,
            });
        } else {
            api.setFrameGroupIndex({
                name: 'nav',
                index: 2,
                reload: true,
            });
        }
    }


    function get_icon() {
      api.ajax({
          url: 'http://www.big-wealth.com/index.php?ctl=app_article&act=images',
          method: 'post',
      },function(ret, err){
          if (ret) {
        dw = ret.dw;
        undw = ret.undw;

        for (var i = 0; i < undw.length; i++) {
          $('#I'+i).attr("src",undw[i].address);
        }

        $('#I0').attr("src",dw[0].address);


          } else {
              alert( JSON.stringify( err ) );
          }
      });

    }


    function setIndex2() {
        api.setFrameGroupIndex({
            name: 'nav',
            index: 2,
            reload: true,
        });
    };
</script>

</html>
